﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace problema3
{
    class RemoteConnection
    {
        public string databasename;
        public ConnectionPool conn_pool;
        public String SendQuery(Query query)
        {
            try
            {
                DataConnection dc = conn_pool.AcquireConnection(databasename);
                string result = dc.SendQuery(query);
                conn_pool.ReleaseConnection(dc);
                return result;
            }
            catch (Exception)
            {
                Console.WriteLine("Nu s-a putut crea conexiunea la baza de date, deoarece aceasta nu exista in pool");
                return null;
            }
        }
        public void afiseaza_conexiuni()        //iterator
        {
            Console.WriteLine("Se pot crea conexiuni catre bazele de date:");
            Iterator  i = conn_pool.createIterator();

            while (i.hasnext())
            {
                DataConnection x = i.next();
                Console.WriteLine(x.getdatabaseName());
            }
            Console.WriteLine("Conexiuni:");
        }
    }
}
